package com.hyx.bookManager.service.impl;

import com.hyx.bookManager.domain.common.CommonResult;
import com.hyx.bookManager.domain.po.MonitorImage;
import com.hyx.bookManager.mapper.MonitorMapper;
import com.hyx.bookManager.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName MonitorServiceImpl
 * @Description TODO
 * @Author 黄乙轩
 * @Date 2021/6/28 22:22
 * @Version 1.0
 **/

@Service
public class MonitorServiceImpl implements MonitorService {

    @Autowired
    private MonitorMapper monitorMapper;

    @Override
    public CommonResult getMonitor(LocalDate start, LocalDate end, Long page, Long pageSize) {
        List<MonitorImage> list = monitorMapper.getMonitor(start,end,(page-1)*pageSize,pageSize);
        return CommonResult.success(list);
    }

    @Override
    public CommonResult getTotalPage(LocalDate startTime, LocalDate endTime, Long page, Long pageSize) {
        Long totalPage = monitorMapper.getTotalPage(startTime,endTime);
        if(totalPage%pageSize==0){
            totalPage /= pageSize;
        }else{
            totalPage = totalPage/pageSize + 1;
        }
        return CommonResult.success(totalPage);
    }
}
